<script type="text/javascript" language="javascript">
function ListingLevel(val)
	{
		if(val==1)
		{
			document.getElementById('premiumid').style.display='none';
		}
		else
		{
			document.getElementById('premiumid').style.display='inline';
		}
	}
	
var wordLimit = 50;
	var holdText;
	var disabledBox = false;
	function countEm()
	{
	 var text1 = document.listingaddform.businessdesc.value;
	 var text2 = text1.replace(/\s+/g, ' ');
	 var text3 = text2.split(' ');
	 var numberOfWords = text3.length;
	 
	 if(numberOfWords == wordLimit)
	 {
	  holdText = text1;
	 }//end if

	
	 //write number of words left to another field
	 if((wordLimit - numberOfWords) <= 0)
	 {
		 document.listingaddform.wordcount.value = 0;
	 }
	 else
	 {
	 	document.listingaddform.wordcount.value = wordLimit - numberOfWords;
	 }
	
	 if(numberOfWords > wordLimit)
	  alert('You have reached the number of words limit');
	}
	
	function doCount(textParam)
	{
	 //replace all instances of one-or-more spaces with a single space
	 var text2 = textParam.replace(/\s+/g, ' ');
	
	 //trim leading and tailing spaces
	 while(text2.substring(0, 1) == ' ')
	  text2 = text2.substring(1);
	 while(text2.substring(text2.length-2, text2.length-1) == ' ')
	  text2 = text2.substring(0,text2.length-1);
	
	 var text3 = text2.split(' ');
	
	 return text3.length;
	}//end function
	
	function maybeReset()
	{
	 if(disabledBox)
	 {
	  var currText = document.listingaddform.ebusinessdesc.value;
	  var newLength = doCount(currText);
	
	  //prevent user from adding words, but not taking them away
	  if(newLength > wordLimit)
	  {
	   document.listingaddform.businessdesc.value = holdText;
	  }//end if
	 }//end if
	}//end function

</script>
<form name="listingaddform" action="index.php?tc=listing_addcode" method="post" enctype="multipart/form-data">
<?php
if($_REQUEST['_s'] == 1)
{?>
<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Submitted successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_e'] == 1)
{?>
<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;Invalid file format.</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_e'] == 2)
{?>
<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;Transcation failed. Please try again.</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="99%" align="center" border="0"  class="list">
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left">Add Business</div>
        <div style="float:right"><a href="index.php?tc=listing">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Business Name</td>
    <td align="left"><input class="text" name="businessname" type="text"/></td>
</tr>
<tr>
	<td align="right" width="150">Business Short Description</td>
    <td align="left"><textarea name="desc" cols="30" rows="4" wrap="soft"></textarea></td>
</tr>
<tr>
	<td align="right" width="150">Opening Hours</td>
    <td align="left"><textarea name="openinghours" cols="30" rows="4" wrap="soft"></textarea></td>
</tr>
<tr>
	<td align="right" width="150">Location</td>
    <td align="left"><input type="text" name="location" class="text"  /></td>
</tr>
<tr>
	<td align="right" width="150">Listing Level</td>
    <td align="left">
	<input type="radio" name="listinglevel" value="1" checked="checked" onClick="ListingLevel(this.value)"  />&nbsp;STANDARD<br />
    <input type="radio" name="listinglevel" value="2" onClick="ListingLevel(this.value)"  />&nbsp;PREMIUM
	</td>
</tr>
<tr>
	<td align="right" width="150" valign="top">Category</td>
	<td align="left">
		<table align="center" border="0" width="100%">
			<tr>
			<?php
				$sql=mysql_query("select * from category");
				while($n=mysql_fetch_array($sql))
				{
			?>
			<td align="left" rowspan="2">
			<input type="checkbox" name="cat[]" value="<?php echo $n['Id'];?>" />&nbsp;<?php echo $n['Name'];?>
			</td>
			</tr>
			<?php } ?>
		</table>
	</td> 
</tr>
<tr>
	<td align="right" width="150">Website URL</td>
    <td align="left">
	<input type="text" name="url" class="text" value="http://"  />
	</td>
</tr>
<tr>
	<td align="right" width="150">Business Logo</td>
    <td align="left"><input type="file" name="logo" /><br>
			<span style="font-size:10px;font-style:italic">Note: JPEG images only</span></td>
</tr>
<tr>
	<td align="right" width="150">Keywords</td>
    <td align="left">
	<textarea name="keywords" cols="30" rows="4" wrap="soft"></textarea>
	</td>
</tr>
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left">Business Template Details</div>
    </td>
</tr>
</thead>
<tr>
	<td  colspan="2" align="center">
	<div id="premiumid" style="display:none">
   <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right"  width="180" valign="top">Image</td>
                    <td align="left">
                        <input type="radio" name="imgpriority" value="1">&nbsp;Priority&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="imgpriority" value="2">&nbsp;Default
                    </td>
                </tr>
                <tr>
                	<td align="right" width="180">Image 1</td>
                    <td align="left"><input type="file" name="tempimage1" /></td>
                </tr>
                <tr>
                	<td align="right" width="180">Image 2</td>
                    <td align="left"><input type="file" name="tempimage2"  /></td>
                </tr>
                </table>
            	<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
                <tr>
                	<td align="right" width="180">Image 3</td>
                    <td align="left"><input type="file" name="tempimage3" /></td>
                </tr>
                <tr>
                	<td align="right" width="180">Image 4</td>
                    <td align="left"><input type="file" name="tempimage4"  /></td>
                </tr>
                <tr>
                	<td align="right" width="180">Image 5</td>
                    <td align="left"><input type="file" name="tempimage5"  /></td>
                </tr>
                <tr>
                	<td align="right" width="180">Image 6</td>
                    <td align="left"><input type="file" name="tempimage6"  />
                    	<br />Note: JPEG and GIF images only
                    </td>
                </tr>    
                </table>
         	</div>       
        </td>
</tr>
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left">Business Contact Details</div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Contact Email</td>
    <td align="left">
	<input type="text" name="contactemail" class="text"  />
	</td>
</tr>
<tr>
	<td align="right" width="150">Show Contact Email</td>
    <td align="left">
	<input type="radio" value="1" name="showcontactemail" />&nbsp;Yes&nbsp;&nbsp;
    <input type="radio" value="0" name="showcontactemail" checked />No
	</td>
</tr>
<tr>
	<td align="right" width="150">Address 1</td>
    <td align="left">
	<input type="text" name="address1" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">Address 2</td>
    <td align="left">
	<input type="text" name="address2" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">City</td>
    <td align="left">
	<input type="text" name="city" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">State</td>
    <td align="left">
	<input type="text" name="state" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">Postcode</td>
    <td align="left">
	<input type="text" name="postcode" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">Phone</td>
    <td align="left">
	<input type="text" name="phone" class="text" />
	</td>
</tr>
<tr>
	<td align="right" width="150">Fax</td>
    <td align="left">
	<input type="text" name="fax" class="text" />
	</td>
</tr>
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left">Business Long Description</div>
    </td>
</tr>
</thead>
<tr>
	<td colspan="2" align="left">
        	<textarea name="businessdesc" cols="100" rows="5" wrap="soft" onkeydown='countEm();' onkeyup='maybeReset();' ></textarea><br />
            <input type="text" name="wordcount" value="50" style="width:30px;" readonly="readonly"  />
    </td>
</tr>
<tr>
    	<td align="left" colspan="2">
        	<input type="submit" value="Save and Submit for Approval" name="save_approval" />&nbsp;<input type="reset" value="Clear" />
        </td>
  	</tr> 
</table>
</form>